{$CLEO .cs}
{$USE CLEO+}
{$USE audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP 

script_name "Strgta4"

if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
then
    if
        0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
    then
        0AA7: call_function_return 30@ num_params 0 pop 0 29@
        if
            not 29@ >= 0x1020000
        then
            0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the DrIVe mod is disabled" time 15000
            0AA3: free_dynamic_library 31@
            0A93: terminate_this_custom_script
        end
        0AA3: free_dynamic_library 31@
    end
else
    0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the DrIVe mod is disabled" time 15000
    0AA3: free_dynamic_library 31@
    0A93: terminate_this_custom_script
end

0AF2: 28@ = get_float_from_ini_file "cleo\startconfig.ini" section "settings" key "Volume"
24@ = 3.0
25@ = 6.0
26@ = 15

const
    Check = 21@
    engine_stat = 31@
    Check_Global = 30@
    radio_off = 27@
end

if
    0E20: is_on_samp
then
    0A93: terminate_this_custom_script
end

while true
wait 0 
if
   Player.Defined($PLAYER_CHAR) 
then
    if and
        8741:   not actor $PLAYER_ACTOR busted
        not actor.Dead($PLAYER_ACTOR)
        not Actor.Driving($PLAYER_ACTOR)
        $ONMISSION == 0
    then
        0E43: get_char_task_pointer_by_id $player_actor 803 store_to 2@ // TASK_SIMPLE_CAR_OPEN_LOCKED_DOOR_FROM_OUTSIDE
        0E43: get_char_task_pointer_by_id $player_actor 800 store_to 1@ // TASK_COMPLEX_GO_TO_CAR_DOOR_AND_STAND_STILL
        if or
            2@ <> 0
            1@ <> 0
        then
            if 1@ <> 0
            then 0D4E: 1@ = read_struct 1@ offset 0xc size 4 // CTaskComplexCarDrive struc -> C m_pVehicle      dd ?
            else 0D4E: 1@ = read_struct 2@ offset 0x10 size 4 // CTaskSimpleCarOpenDoorFromOutside struc -> 10 m_pEntity       dd ?
            end
            0AEB: 6@ = vehicle_struct 1@ handle
            0E12: get_vehicle 6@ subclass_to 1@
            if or
                1@ == 0
                1@ == 9
                1@ == 2
            then

                0A97: 20@ = car 6@ struct
                0D4E: 23@ = struct 20@ offset 0x428 size 1 // Engine State
                    if or
                        23@ == 0 // garage car engine off
                        23@ == 128 // street car engine off
                        23@ == 160 //  street bike engine off
                        23@ == 32  // garage bike engine off
                    then
                        if and
                            0EE5: locate_char_distance_to_car $PLAYER_ACTOR car 6@ radius 6.0
                            not Car.Wrecked(6@)
                            81F4:   not car 6@ flipped
                            82BF:   not car 6@ sunk
                            8495:   not car 6@ burning
                        then
                            if or
                                23@ == 128
                                23@ == 160
                            then
                                0D4E: 22@ = struct 20@ offset 0x4A4 size 1 //  m_nCreatedBy    db ?
                                if
                                    not 22@ == 3 // 3 - PARKED_VEHICLE
                                then
                                    continue
                                end
                            end
                            0A97: 1@ = vehicle 6@ struct
                            1@ += 0x138
                            1@ += 0xA4

                    repeat
                    wait 0
                        if
                            056E:   car 6@ defined
                        then
                            067F: set_car 6@ lights 1
                            
                            if
                                0E49: is_char_entering_any_car $PLAYER_ACTOR
                            then
                                0A8C: write_memory 1@ size 1 value 0 virtual_protect 0
                            end
                            
                            14@ = -1

                            //
                            if or
                                23@ == 128
                                23@ == 0
                            then
                                if
                                    00DB:   actor $PLAYER_ACTOR in_car 6@
                                then
                                    0A8C: write_memory 1@ size 1 value 1 virtual_protect 0
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                                    0ABF: set_car 6@ engine_state_to 0
                                    051E: radio_off = get_current_radio_station
                                    041E: set_radio_station 12

                                repeat
                                wait 0
                                04ED: load_animation  "DrIVeMod"
                                until 04EE:   animation "DrIVeMod" loaded
                                
                            if 056E:   car 6@ defined
                            then
                            else break
                            end

                            // 
                            if
                                23@ == 128
                            then
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "CAR_Lsit"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_L"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_R"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_drive"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_L"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_R"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4LOW" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                else
                                    if or
                                        Actor.Animation($PLAYER_ACTOR) == "QUAD_Ride"
                                        Actor.Animation($PLAYER_ACTOR) == "QUAD_Left"
                                        Actor.Animation($PLAYER_ACTOR) == "QUAD_Right"  
                                    then
                                        0605: actor $PLAYER_ACTOR perform_animation "startgta4Wayfare" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1    
                                    else
                                        0605: actor $PLAYER_ACTOR perform_animation "startgta41" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                    end
                                end
                                
                            0AC1: 14@ = load_audio_stream_with_3d_support "CLEO/SoundsQa/STARTER.mp3" // IF and SET
                            0AC5: link_3d_audio_stream 14@ to_car 6@
                            0006: TIMERA = 0
                            29@ = 0
                                
                            repeat
                            wait 0
                                gosub @In_Car
                                if
                                    check == false
                                then
                                    break
                                end
                                    041E: set_radio_station 12
                                
                               if and
                                    0019:   TIMERA > 500
                                    29@ == 0
                                then
                                    29@ = 1
                                    0AAD: set_audio_stream 14@ state 1
                                    0ABC: set_audio_stream 14@ volume 28@
                                end
                                
                                if
                                    0019:   TIMERA > 2100
                                then
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                    0ABF: set_car 6@ engine_state_to 1
                                    067F: set_car 6@ lights 0
                                    wait 500
                                        if
                                            056E:   car 6@ defined
                                        then
                                            041E: set_radio_station radio_off
                                        end
                                    0AAD: set_audio_stream 14@ state 0
                                    break
                                end
                            until not player.Defined(0)
                                gosub @Wrong
                                    break
                                
                                
                            // 
                            else
                            
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "CAR_Lsit"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_L"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_R"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4LOWG" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                else
                                    if or
                                        Actor.Animation($PLAYER_ACTOR) == "KART_drive"
                                        Actor.Animation($PLAYER_ACTOR) == "KART_L"
                                        Actor.Animation($PLAYER_ACTOR) == "KART_R"
                                    then
                                        0605: actor $PLAYER_ACTOR perform_animation "startgta4KartG" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                    else
                                        0605: actor $PLAYER_ACTOR perform_animation "startgta4garage" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                    end
                                end
                                
                            0006: TIMERA = 0

                            repeat
                            wait 0
                                gosub @In_Car
                                if
                                    check == false
                                then
                                    break
                                end
                                041E: set_radio_station 12
                            
                                if
                                    0019:   TIMERA > 700
                                then
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                    067F: set_car 6@ lights 0
                                    0ABF: set_car 6@ engine_state_to 1
                                    wait 500
                                        if
                                            056E:   car 6@ defined
                                        then
                                            041E: set_radio_station radio_off
                                        end
                                    break
                                end
                            until not player.Defined(0)
                                gosub @Wrong
                                    break
                            end
                        end
                    end


                            // 
                            if or
                                23@ == 32
                                23@ == 160
                            then
                                if
                                    00DB:   actor $PLAYER_ACTOR in_car 6@
                                then
                                    0A8C: write_memory 1@ size 1 value 1 virtual_protect 0
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                                    051E: radio_off = get_current_radio_station
                                    041E: set_radio_station 12
                                    02D4: car 6@ turn_off_engine
                                    
                                repeat
                                wait 0
                                04ED: load_animation  "DrIVeMod"
                                until 04EE:   animation "DrIVeMod" loaded
                                
                                if 056E:   car 6@ defined
                                then
                                else break
                                end
                                
                                
                                    if or
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Still"
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Ride"
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Right"
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Left"
                                    then
                                        0209: 19@ = random_int_in_ranges 1 3
                                            if
                                                19@ == 1
                                            then
                                                0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes1" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                            else
                                                0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes11" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                            end

                                    0006: TIMERA = 0
                                    29@ = 0


                                    repeat
                                    wait 0
                                        gosub @In_Car
                                        if
                                            check == false
                                        then
                                            break
                                        end
                                            041E: set_radio_station 12
                                            if
                                                0019:   TIMERA > 1050
                                            then
                                                06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                                0209: 7@ = random_int_in_ranges 0 12
                                                041E: set_radio_station 7@
                                                0ABF: set_car 6@ engine_state_to 1
                                                067F: set_car 6@ lights 0
                                                wait 500
                                                    if
                                                        056E:   car 6@ defined
                                                    then
                                                        072A: put_actor $PLAYER_ACTOR into_car 6@ driverseat
                                                        041E: set_radio_station radio_off
                                                    end
                                                break
                                            end
                                                    04BA: set_car 6@ speed_to 0.0
                                    until not player.Defined(0)
                                        gosub @Wrong
                                            break

                            else
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Left"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes3" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                end
                                
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Left"
                                then
                                    0209: 19@ = random_int_in_ranges 1 3
                                        if
                                            19@ == 1
                                        then
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Pizza" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        else
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Pizza2" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        end
                                    end
                                    
                                    
                                 if or
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Left"
                                then
                                    0209: 19@ = random_int_in_ranges 1 3
                                        if
                                            19@ == 1
                                        then
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Wayfare" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        else
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Wayfare2" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        end
                                    end
                                    
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Left"
                                then
                                    0209: 19@ = random_int_in_ranges 1 3
                                        if
                                            19@ == 1
                                        then
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes2" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        else
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes22" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        end
                                    end
                                    
                                0006: TIMERA = 0
                                29@ = 0

                                repeat
                                wait 0
                                    gosub @In_Car
                                    if
                                        check == false
                                    then
                                        break
                                    end
                                        041E: set_radio_station 12
                                        if
                                            0019:   TIMERA > 1050
                                        then
                                            06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                            0ABF: set_car 6@ engine_state_to 1
                                            067F: set_car 6@ lights 0
                                            wait 500
                                                if
                                                    056E:   car 6@ defined
                                                then
                                                    072A: put_actor $PLAYER_ACTOR into_car 6@ driverseat
                                                    041E: set_radio_station radio_off
                                                end
                                            break
                                        end
                                                04BA: set_car 6@ speed_to 0.0
                                until not player.Defined(0)
                                    gosub @Wrong
                                        break
                                end
                            end
                        end


                        else
                        break
                        end
                        until not locate_char_distance_to_car $PLAYER_ACTOR car 6@ radius 6.0
                        end
                    end
                end
            end
    else
        if and
            8741:   not actor $PLAYER_ACTOR busted
            not actor.Dead($PLAYER_ACTOR)
            Actor.Driving($PLAYER_ACTOR)
        then
            0AAA: 1@ = get_script_struct_named "SPEEDO"
            if
                not 1@ == 0
            then
                0AF0: 1@ = read_int_from_ini_file "cleo\Speedometer.ini" section "Keys" key "Engine"
                0@ = Actor.CurrentCar($PLAYER_ACTOR)
                if 0ABE:   car 0@ engine_on
                then engine_stat = true
                else engine_stat = false
                end
                
                repeat
                wait 0
                04ED: load_animation  "DrIVeMod"
                until 04EE:   animation "DrIVeMod" loaded
                
                timera = 0
                repeat
                wait 0
                gosub @Check_Global
                    if
                        Check_Global == true
                    then
                        if and
                            timera > 300
                            0AB0:   is_key_pressed 1@
                        then
                            if
                                engine_stat == true
                            then
                                if
                                    8ABE:   not car 0@ engine_on
                                then
                                    gosub @Animation_on_off
                                    engine_stat = false
                                    timera = 0
                                end
                            end
                            if
                                engine_stat == false
                            then
                                if
                                    0ABE:   car 0@ engine_on
                                then
                                    gosub @Animation_on_off
                                    engine_stat = true
                                    timera = 0
                                end
                            end
                        end
                    else
                        break
                    end
                until not player.Defined(0)
                04EF: release_animation "DrIVeMod"
                end
            end
        end
    end
end

:Check_Global
Check_Global = false
    if and
        Actor.Driving($PLAYER_ACTOR)
        8741:   not actor $PLAYER_ACTOR busted
        not actor.Dead($PLAYER_ACTOR)
    then
        if and
            84C8:   not actor $PLAYER_ACTOR driving_flying_vehicle
            84A7:   not actor $PLAYER_ACTOR driving_boat
            84A9:   not actor $PLAYER_ACTOR driving_heli
            89AE:   not actor $PLAYER_ACTOR driving_train
        then
            0@ = Actor.CurrentCar($PLAYER_ACTOR)
            0E12: get_vehicle 0@ subclass_to 2@
            if or
                2@ == 1
                2@ == 9
                2@ == 0
                2@ == 2
            then
                Check_Global = true
            end
        end
    end
return


:Animation_on_off
if or
    2@ == 9
    2@ == 2
then
    if or
        Actor.Animation($PLAYER_ACTOR) == "BIKES_Still"
        Actor.Animation($PLAYER_ACTOR) == "BIKES_Ride"
        Actor.Animation($PLAYER_ACTOR) == "BIKES_Right"
        Actor.Animation($PLAYER_ACTOR) == "BIKES_Left"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes1" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end

    if or
        Actor.Animation($PLAYER_ACTOR) == "BIKEH_Still"
        Actor.Animation($PLAYER_ACTOR) == "BIKEH_Ride"
        Actor.Animation($PLAYER_ACTOR) == "BIKEH_Right"
        Actor.Animation($PLAYER_ACTOR) == "BIKEH_Left"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes3" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end

    if or
        Actor.Animation($PLAYER_ACTOR) == "BIKEV_Still"
        Actor.Animation($PLAYER_ACTOR) == "BIKEV_Ride"
        Actor.Animation($PLAYER_ACTOR) == "BIKEV_Right"
        Actor.Animation($PLAYER_ACTOR) == "BIKEV_Left"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4Pizza" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end


     if or
        Actor.Animation($PLAYER_ACTOR) == "WF_Still"
        Actor.Animation($PLAYER_ACTOR) == "WF_Ride"
        Actor.Animation($PLAYER_ACTOR) == "WF_Right"
        Actor.Animation($PLAYER_ACTOR) == "WF_Left"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4Wayfare" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end

    if or
        Actor.Animation($PLAYER_ACTOR) == "BIKED_Still"
        Actor.Animation($PLAYER_ACTOR) == "BIKED_Ride"
        Actor.Animation($PLAYER_ACTOR) == "BIKED_Right"
        Actor.Animation($PLAYER_ACTOR) == "BIKED_Left"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes2" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end
    
    if or
        Actor.Animation($PLAYER_ACTOR) == "QUAD_Ride"
        Actor.Animation($PLAYER_ACTOR) == "QUAD_Left"
        Actor.Animation($PLAYER_ACTOR) == "QUAD_Right"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4garage" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end
end
                                    
if or
    2@ == 0
    2@ == 1
then
    if or
        Actor.Animation($PLAYER_ACTOR) == "CAR_Lsit"
        Actor.Animation($PLAYER_ACTOR) == "Drive_LO_L"
        Actor.Animation($PLAYER_ACTOR) == "Drive_LO_R"
    then
        0605: actor $PLAYER_ACTOR perform_animation "startgta4LOWG" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    else
        if or
            Actor.Animation($PLAYER_ACTOR) == "KART_drive"
            Actor.Animation($PLAYER_ACTOR) == "KART_L"
            Actor.Animation($PLAYER_ACTOR) == "KART_R"
        then
            0605: actor $PLAYER_ACTOR perform_animation "startgta4KartG" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
        else
            0605: actor $PLAYER_ACTOR perform_animation "startgta4garage" IFP "DrIVeMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
        end
    end
    
end
return

:Wrong
    if
        056E:   car 6@ defined
    then
        067F: set_car 6@ lights 0
    end
06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
0687: clear_actor $PLAYER_ACTOR task
if not 14@ == -1
then 0AAE: remove_audio_stream 14@
end
04EF: release_animation "DrIVeMod"
return
   
   
:In_Car
Check = true
    if or
        Actor.Dead($PLAYER_ACTOR)
        0741:   actor $PLAYER_ACTOR busted
        not Actor.Driving($PLAYER_ACTOR)
        00E1:   player 0 pressed_key 26@
        0E4A: is_char_exiting_any_car $PLAYER_ACTOR
        856E:   not car 6@ defined
    then
        Check = false
    end
return
   
   